package com.aishuang.order.config;

import com.alibaba.cloud.nacos.ribbon.NacosRule;
import com.netflix.loadbalancer.*;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @Title: RestTemplateConfig
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/3/6 9:33
 */
@Configuration
public class RestTemplateConfig {

    @Bean
    @LoadBalanced  // 负载均衡
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /**
     * 配置负载均衡策略
     * @return
     */
    @Bean
    public IRule myRule() {
        // 配置轮训策略
       // return new RoundRobinRule();  // 轮训
       // return new RandomRule();  // 随机
        // return new NacosRule();  // 同集群的优先访问
        // return new WeightedResponseTimeRule();
        return new ZoneAvoidanceRule();

    }
}
